package com.zlm.stream;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Arrays;
import java.util.List;

/**
 * @Author: 郑
 * .要求： 一行代码实现
 * 现有5个用户：筛选：
 * 1 ID 必须是偶数
 * 2 年龄大于23
 * 3 用户名转为大写
 * 4 根据用户名倒序
 * 5 输出一个用户
 *
 */
public class StreamDemo {
    public static void main(String[] args) {
        User a = new User(1, "a", 20);
        User b = new User(2, "b", 21);
        User c = new User(3, "c", 23);
        User d = new User(4, "d", 25);
        User e = new User(6, "e", 26);
        List<User> list = Arrays.asList(a, b, c, d, e);
        list.stream().filter((u) -> {
            return (u.getId() & 1) == 0 && u.getAge()>23;
        }).map((u) ->{return u.getName().toUpperCase();}).sorted((u1,u2) ->{ return u2.compareTo(u1);}).limit(1).forEach(System.out::println);
    }
}
@Data
@AllArgsConstructor
@NoArgsConstructor
class User{
    private Integer id;
    private String name;
    private int age;

}